<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 *@param string $url: 发送请求的链接
 *@param int $httpCode: 返回的状态码
 */
function curl_get($url, &$httpCode = 0)
{
//    $url = "https://api.weixin.qq.com/sns/jscode2session?appid=wxda770323d3079560&secret=2b6f2f74625a133e96d2227e82c5782d&js_code=081SqeaD0d9zyd2EL27D0EGfaD0Sqeat&grant_type=authorization_code";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //如果不做证书校验，部署在Linux环境下请改为ture
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $file_contents = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return json_decode($file_contents, true);
}

//获取随机32位字符1
function getRandChars($length = 0)
{
    $str = '';
    $strpoll = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz';
    $maxlength = strlen($strpoll) - 1;
    for($i = 0; $i < $length; $i++)
    {
        $str .= $strpoll[rand(0, $maxlength)];
    }
    return $str;

}
